package com.ruoyi.livedemo.controller;

import com.ruoyi.livedemo.common.ApiResponse;
import com.ruoyi.livedemo.context.CurrentUserHolder;
import com.ruoyi.livedemo.dto.PartnerEvaluationRequest;
import com.ruoyi.livedemo.entity.PartnerEvaluation;
import com.ruoyi.livedemo.service.EvaluationService;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/evaluations")
public class EvaluationController {

    private final EvaluationService evaluationService;

    @GetMapping
    public ApiResponse<PartnerEvaluation> get() {
        Long userId = CurrentUserHolder.getUserId();
        return ApiResponse.ok(evaluationService.latest(userId));
    }

    @PostMapping
    public ApiResponse<PartnerEvaluation> save(@Valid @RequestBody PartnerEvaluationRequest request) {
        Long userId = CurrentUserHolder.getUserId();
        return ApiResponse.ok("Evaluation saved", evaluationService.save(userId, request));
    }
}

